package cn.initcap.controller;

import cn.initcap.common.Result;
import cn.initcap.service.SeckillUserService;
import cn.initcap.vo.LoginVo;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author initcap
 * @date 2018/8/10 PM3:03
 */
@Slf4j
@Controller
@RequestMapping("/login")
public class LoginController {

    private SeckillUserService userService;

    @Autowired
    public LoginController(SeckillUserService userService) {
        this.userService = userService;
    }

    @RequestMapping("/to_login")
    public String toLogin() {
        return "login";
    }

    @RequestMapping("/do_login")
    @ResponseBody
    public Result doLogin(HttpServletResponse response, @Valid LoginVo loginVo) {
        log.info(loginVo.toString());
        //登录
        String token = userService.login(response, loginVo);
        return Result.success(token);
    }
}
